
<template>
	<!-- 添加每日菜品 -->
	<div>
		<el-row>
			<el-col :span="3">
				<span class="formLable must">选择餐点</span>
			</el-col>
			<el-col :span="21">
				<el-checkbox-group v-model="checkList" @change="mealsChange">
					<el-checkbox label="早餐"></el-checkbox>
					<el-checkbox label="午餐"></el-checkbox>
					<el-checkbox label="晚餐"></el-checkbox>
				</el-checkbox-group>
			</el-col>
		</el-row>

		<el-row v-for="(row,index) in selectData" :key="index">
			<el-row>
				<span class="title">{{row.mealsName}}</span>
			</el-row>
			<el-row>
				<el-col :span="3">
					<span class="formLable must">菜品介绍</span>
				</el-col>
				<el-col :span="21">
					<el-input
						type="textarea"
						:rows="2"
						maxlength="50"
						show-word-limit
						placeholder="请输入内容"
						v-model="row.introduce">
					</el-input>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="3">
					<span class="formLable must">缩略图</span>
				</el-col>
				<el-col :span="21">
					<imageUpload :type="'image'" :maxSize="2" v-model="row.imageUrl"></imageUpload>
				</el-col>
			</el-row>
		</el-row>
		
		<el-row style="text-align:center;">
			<el-button @click="cancle">取消</el-button>
			<el-button @click="save">确定</el-button>
		</el-row>
	</div>
</template>

<script>
	let vm;
	import imageUpload from '@/components/common/image_upload'
	export default{
		components:{imageUpload},
		data(){
			return {
				checkList:[],
				selectData:[]
			}
		},
		methods:{
			init(data){
				this.checkList=[];
				this.selectData=[];
				if(data){
					this.checkList=data.checkList||[];
					this.selectData=data.selectData||[];
				}
			},
			mealsChange(list){
				// debugger
				this.selectData=[];
				if(list&&list.length>0){
					for(let i=0,count=list.length;i<count;i++){
						let row=list[i];
						this.selectData.push({
							mealsName:row,
							introduce:'',
							imageUrl:[],
						});
					}
				}
			},
			cancle(){
				this.$emit('cancle',false);
			},
			save(){
				let length=this.selectData.length;
				if(length<=0){
					this.$message({
						type:'warning',
						message:'请选择餐点！'
					})
					return;
				}
				
				for(let i=0;i<length;i++){
					let row=this.selectData[i];
					if(!row.introduce){
						this.$message({
							type:'warning',
							message:'请输入'+row.mealsName+'的菜品介绍！'
						})
						return;
					}
					if(!row.imageUrl||row.imageUrl.length==0){
						this.$message({
							type:'warning',
							message:'请上传'+row.mealsName+'的缩略图！'
						})
						return;
					}
				}

				this.$emit('cancle',false);
			},
		},
		mounted(){
			vm=this;
		},
		computed:{
			
		},
		watch:{

		}
	}
</script>

<style lang="scss" scoped>
	.formLable,.formValue{
		font-size: 0.16rem;
		line-height: 0.4rem;
	}
	.formLable.must::before{
		content: '*';
		color: red;
		margin: 0 0.05rem;
	}
	.el-row{
		margin-bottom: 0.16rem;
	}
	.el-checkbox{
		font-size: 0.16rem;
		line-height: 0.4rem;
	}
</style>